package de.alfenory.autobill.entity;

import java.util.*;

/**
 * @author alefen
 */
public class Autobill {

    List<BookEntry> bookEntryList;
    List<AutobillDetail> autobillDetailList;
    double value;
    boolean taxIncluded;
    double vatValue;
    Date transdate;
    Date duedate;
    String reference;
    String paymentTerm;
    
    public Autobill() {
        this.bookEntryList = new ArrayList<BookEntry>();
        this.autobillDetailList = new ArrayList<AutobillDetail>();
        this.value = 0;
        this.vatValue = 0;
        this.taxIncluded = true;
        this.reference = "";
        this.paymentTerm = "";
        this.duedate = null;
    }

    public List<BookEntry> getBookEntryList() {
        return bookEntryList;
    }

    public List<AutobillDetail> getAutobillDetailList() {
        return autobillDetailList;
    }

    public void setValue(double value) {
        this.value = value;
    }

    public void setVatValue(double vatValue) {
        this.vatValue = vatValue;
    }

    public void setTransdate(Date transdate) {
        this.transdate = transdate;
    }

    public void setTaxIncluded(boolean taxIncluded) {
        this.taxIncluded = taxIncluded;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public void setPaymentTerm(String paymentTerm) {
        this.paymentTerm = paymentTerm;
    }

    public String getPaymentTerm() {
        return paymentTerm;
    }

    public Date getTransdate() {
        return transdate;
    }

    public double getValue() {
        return value;
    }

    public double getVatValue() {
        return vatValue;
    }

    public Date getDuedate() {
        return duedate;
    }

    public void setDuedate(Date duedate) {
        this.duedate = duedate;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + Objects.hashCode(this.bookEntryList);
        hash = 59 * hash + Objects.hashCode(this.autobillDetailList);
        hash = 59 * hash + (int) (Double.doubleToLongBits(this.value) ^ (Double.doubleToLongBits(this.value) >>> 32));
        hash = 59 * hash + (this.taxIncluded ? 1 : 0);
        hash = 59 * hash + (int) (Double.doubleToLongBits(this.vatValue) ^ (Double.doubleToLongBits(this.vatValue) >>> 32));
        hash = 59 * hash + Objects.hashCode(this.transdate);
        hash = 59 * hash + Objects.hashCode(this.duedate);
        hash = 59 * hash + Objects.hashCode(this.reference);
        hash = 59 * hash + Objects.hashCode(this.paymentTerm);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Autobill other = (Autobill) obj;
        if (!Objects.equals(this.bookEntryList, other.bookEntryList)) {
            return false;
        }
        if (!Objects.equals(this.autobillDetailList, other.autobillDetailList)) {
            return false;
        }
        if (Double.doubleToLongBits(this.value) != Double.doubleToLongBits(other.value)) {
            return false;
        }
        if (this.taxIncluded != other.taxIncluded) {
            return false;
        }
        if (Double.doubleToLongBits(this.vatValue) != Double.doubleToLongBits(other.vatValue)) {
            return false;
        }
        if (!Objects.equals(this.transdate, other.transdate)) {
            return false;
        }
        if (!Objects.equals(this.duedate, other.duedate)) {
            return false;
        }
        if (!Objects.equals(this.reference, other.reference)) {
            return false;
        }
        if (!Objects.equals(this.paymentTerm, other.paymentTerm)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        String bookentrystr = "";
        for(BookEntry be : bookEntryList) {
            bookentrystr += be.toString()+"\n";
        }
        String autobilldetailstr = "";
        for(AutobillDetail ad : autobillDetailList) {
            autobilldetailstr += ad.toString()+"\n";
        }
        return "Autobill{\n reference:" + reference + ",value:" + value + ", taxIncluded:" + taxIncluded + ", vatValue:" + vatValue + ", transdate:" + transdate + ", duedate:" + duedate + ", paymentTerm:" + paymentTerm +"\n bookEntryList:" + bookentrystr + ",\n autobillDetailList=" + autobilldetailstr + "}";
    }

    public boolean isTaxIncluded() {
        return taxIncluded;
    }
}